package com.joysuch.wwyt.api.sync.controller;


import com.joysuch.wwyt.api.sync.service.*;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.support.Context;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "/api 数据同步接口")
@RequestMapping("/api/sync")
public class BaseDataSyncController {

    @Autowired
    private BaseSyncEquipmentService syncEquipmentService;

    @Autowired
    private BaseSyncUserService syncUserService;

    @Autowired
    private BaseSyncContractorService syncContractorService;

    @Autowired
    private BaseSyncContractorStaffService syncContractorStaffService;

    @Autowired
    private BaseSyncUserCertService baseSyncUserCertService;

    @Autowired
    private BaseSyncCreditCardRecordService baseSyncCreditCardRecordService;

    @Autowired
    private BaseSyncCardRecordService baseSyncCardRecordService;


    @GetMapping("syncEquip")
    @RequiresPermissions("api:sync:sync-equip")
    public ResultBean syncEquip() {
        String companyCode = Context.getCompanyCode();
       return syncEquipmentService.syncEquipmentByCompany(companyCode);

    }

    @GetMapping("syncUser")
    @RequiresPermissions("api:sync:sync-user")
    public ResultBean syncUser() {
        String companyCode = Context.getCompanyCode();
       return syncUserService.syncUserByCompany(companyCode);

    }

    @GetMapping("syncUserCert")
    @RequiresPermissions("api:sync:sync-user-cert")
    public ResultBean syncUserCert() {
        String companyCode = Context.getCompanyCode();
        return baseSyncUserCertService.syncUserCertByCompany(companyCode, true);

    }

    @GetMapping("syncContract")
    @RequiresPermissions("api:sync:sync-contract")
    public ResultBean syncContract() {
        String companyCode = Context.getCompanyCode();
        return syncContractorService.syncContractorByCompany(companyCode);

    }


    @GetMapping("syncContractStaff")
    @RequiresPermissions("api:sync:sync-contract-staff")
    public ResultBean syncContractStaff() {
        String companyCode = Context.getCompanyCode();
        return syncContractorStaffService.syncContractorStaffByCompany(companyCode);

    }

    @GetMapping("syncContractStaffCert")
    @RequiresPermissions("api:sync:sync-contract-staff-cert")
    public ResultBean syncContractStaffCert() {
        String companyCode = Context.getCompanyCode();
        return baseSyncUserCertService.syncUserCertByCompany(companyCode,false);

    }

    //卡口信息同步
    @GetMapping("syncCreditCardRecord")
    @RequiresPermissions("api:sync:sync-credit-card-record")
    public ResultBean syncCreditCardRecord() {
        String companyCode = Context.getCompanyCode();
        Integer typeFlag =0;
        return baseSyncCreditCardRecordService.syncCreditCardRecordByCompany(companyCode,typeFlag);
    }

    //卡口信息同步
    @GetMapping("syncCreditCardRecords")
    @RequiresPermissions("api:sync:sync-credit-card-records")
    public ResultBean syncCreditCardRecords() {
        return baseSyncCreditCardRecordService.syncCreditCardRecord();
    }


    //车辆出入记录信息同步
    @GetMapping("syncCarRecord")
    @RequiresPermissions("api:sync:sync-car-record")
    public ResultBean syncCarRecord() {
        String companyCode = Context.getCompanyCode();
        Integer typeFlag =1;
        return baseSyncCardRecordService.syncCreditCardRecordByCompany(companyCode,typeFlag);
    }

    //车辆出入记录信息同步
    @GetMapping("syncCarRecords")
    @RequiresPermissions("api:sync:sync-car-records")
    public ResultBean syncCarRecords() {
        return baseSyncCardRecordService.syncCreditCardRecord();
    }

}
